#encoding=utf-8
#计算由序列里N-1个数字相乘最大的值

def max2(a):
    '''unittest
    >>> max2([3,2,1,4])
    24
    >>> max2([3,2,1])
    6
    >>> max2([0,3,2,1])
    6
    >>> max2([0,0,3,2,1])
    0
    >>> max2([0,-3,2,1])
    0
    >>> max2([0,-2,-3,2,1])
    12
    >>> max2([2,-2,-3,2,1])
    24
    '''
    a1 = []
    a2 = []
    a0 = []
    for i in a:
      if i < 0:
          a1.append(i)
      elif i > 0:
          a2.append(i)
      else:
          a0.append(0)
    

    
    if len(a0) == 1:
        if len(a1)%2==0:
            return chengfa1(a1,a2)
        else:
            return 0
        
    if len(a0) >= 2:
        return 0
    
    if len(a0) == 0:
        if len(a1)%2 == 1:
            a1.pop(a1.index(max(a1)))
            return chengfa1(a1,a2)
        else:
            if len(a2) >= 1:
                a2.pop(a2.index(min(a2)))
                return chengfa1(a1,a2)
            else:
                a1.pop(a1.index(min(a1)))
                return chengfa1(a1,a2)
        
def chengfa1(a,b):
    r = 1
    for i in a:
        r = r * i
    for j in b:
        r = r * j
    return r

import doctest
doctest.testmod()